<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/26
 * Time: 21:52
 */
namespace app\admin\model;
use think\Db;

class User extends \app\index\model\Base{
    public function __construct()
    {
         $this->setTableName("user");
    }

    /*
     * 获取用户基本信息跟分享关注数据
     * */
    public function getUserInfoAndShareDetail($day=""){
        $day=$day ? $day : date("Y-m-d",time());
     return   Db::name($this->getTableName())
            ->alias("a")
            ->join("count_user_share_detail b","a.openid=b.openid")
            ->field("a.*,b.num")
            ->where(["b.day"=>$day])
            ->order("num desc")
            ->paginate(10);

    }

    /*
     * 获取用户画像
     * */
    public function getUserShareViewByTime($openid){
        return Db::name("user_share_detail")
            ->field("FROM_UNIXTIME(add_time,'%Y-%m-%d %H') time,count(id) num ")
            ->where(["openid"=>$openid])
            ->group("time")
            ->order("id desc")
            ->select();
    }

}